package version

import (
	"fmt"
	"runtime"
)

var (
	// Version 应用版本号
	Version = "1.0.0"
	// GitCommit Git提交哈希
	GitCommit = "dev"
	// BuildTime 构建时间
	BuildTime = "unknown"
	// GoVersion Go版本
	GoVersion = runtime.Version()
	// Platform 平台信息
	Platform = fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
)

// Info 版本信息结构
type Info struct {
	Version   string `json:"version"`
	GitCommit string `json:"git_commit"`
	BuildTime string `json:"build_time"`
	GoVersion string `json:"go_version"`
	Platform  string `json:"platform"`
}

// GetVersion 获取版本信息
func GetVersion() Info {
	return Info{
		Version:   Version,
		GitCommit: GitCommit,
		BuildTime: BuildTime,
		GoVersion: GoVersion,
		Platform:  Platform,
	}
}

// String 返回版本信息字符串
func (v Info) String() string {
	return fmt.Sprintf("Collector %s (commit: %s, built: %s, go: %s, platform: %s)",
		v.Version, v.GitCommit, v.BuildTime, v.GoVersion, v.Platform)
}

// ShortString 返回简短版本信息
func (v Info) ShortString() string {
	return fmt.Sprintf("Collector %s", v.Version)
}
